{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d7fb2169",
   "metadata": {
    "pycharm": {
     "is_executing": true,
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "#导入相关库\n",
    "import pandas as pd\n",
    "import sqlalchemy\n",
    "from pyecharts.components import Table\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Line,  Bar\n",
    "import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "86549490",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "#获取数据\n",
    "def read_data(table):\n",
    "    sql = \"SELECT * FROM \" + table\n",
    "    # 设置openGauss数据库版本信息\n",
    "    from sqlalchemy.dialects.postgresql.base import PGDialect\n",
    "    PGDialect._get_server_version_info = lambda *args: (9, 2)\n",
    "    userName = 'myroot'\n",
    "    password = 'myroot_123'\n",
    "    dbHost = '10.10.74.207'\n",
    "    dbPort = 15400\n",
    "    dbName = 'app'\n",
    "    DB_CONNECT = f'postgresql://{userName}:{password}@{dbHost}:{dbPort}/{dbName}'\n",
    "    conn_new = sqlalchemy.create_engine(DB_CONNECT)\n",
    "    if conn_new:\n",
    "        print(\"连接数据库成功\")\n",
    "    df = pd.read_sql(sql, conn_new)\n",
    "    print(df.columns)\n",
    "    return df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3ad17458",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "连接数据库成功\n",
      "Index(['id', 'selfid', 'name', 'addr'], dtype='object')\n",
      "连接数据库成功\n",
      "Index(['id', 'companyid', 'name', 'equipmentnumber'], dtype='object')\n",
      "连接数据库成功\n",
      "Index(['id', 'datetime', 'equipmentnumber', 'worktime', 'standbytime'], dtype='object')\n"
     ]
    }
   ],
   "source": [
    "# 读取公司信息CompanyInfos，设备信息InstallInfos，运行时间信息TimeInfos，删除id列\n",
    "CompanyInfos = read_data('companyinfos')\n",
    "CompanyInfos.drop(columns='id', inplace=True)\n",
    "InstallInfos = read_data('installinfos')\n",
    "InstallInfos.drop(columns='id', inplace=True)\n",
    "TimeInfos = read_data('timeinfos')\n",
    "TimeInfos.drop(columns='id', inplace=True)\n",
    "# 将表中的数据'worktime','standbytime'转换成浮点数\n",
    "TimeInfos['worktime'] = TimeInfos['worktime'].astype('float64')\n",
    "TimeInfos['standbytime'] = TimeInfos['standbytime'].astype('float64')\n",
    "# 计算所需的 每天停机时间:'stoptime',开机率'startrate',工作效率:'efficiency'\n",
    "TimeInfos['stoptime'] = round(24 - (TimeInfos['worktime'] + TimeInfos['standbytime']), 2)\n",
    "TimeInfos['startrate'] = round(((TimeInfos['worktime'] + TimeInfos['standbytime']) / 24) * 100, 2)\n",
    "TimeInfos['efficiency'] = round(TimeInfos['worktime'] / (TimeInfos['worktime'] + TimeInfos['standbytime']) * 100, 2)\n",
    "TimeInfos.fillna(0, inplace=True)\n",
    "# 获取TimeInfos表中的最大日期，并筛选出该日期对应的数据保存在day_timeinfos变量中\n",
    "date = TimeInfos['datetime'].max()\n",
    "day_timeinfos = TimeInfos[TimeInfos['datetime'] == date]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "f7ba0f1a",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "cname = \"江苏兴荣高新科技股份有限公司\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "3f6dfcbb",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "def company_info(cname, date):\n",
    "    # 公司id\n",
    "    cid = CompanyInfos[CompanyInfos['name'] == cname]['selfid'].to_list()[0]\n",
    "    # 公司所有设备\n",
    "    cinstallinfos = InstallInfos[InstallInfos['companyid'] == cid]\n",
    "    # 公司设备对应运行时间\n",
    "    tinfos = TimeInfos[TimeInfos['datetime'] == date]\n",
    "    # 合并设备信息和设备运行信息\n",
    "    cinfos = cinstallinfos.join(tinfos.set_index('equipmentnumber'), on='equipmentnumber')\n",
    "    cinfos.drop(columns=['datetime', 'companyid'], inplace=True)\n",
    "    cinfos = cinfos.fillna(0)\n",
    "    cinfos['stoptime'] = round(24 - (cinfos['worktime'] + cinfos['standbytime']), 2)\n",
    "    return cinfos"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "f6cc9ea7",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "#获取昨天的时间\n",
    "date = (datetime.datetime.now() + datetime.timedelta(days=-1)).strftime('%Y-%m-%d')\n",
    "maxdate = TimeInfos['datetime'].max()\n",
    "if date is None or date == '':\n",
    "    date = maxdate\n",
    "if date > maxdate:\n",
    "    date = maxdate\n",
    "cinfos = company_info(cname, date)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "6a13ba0e",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "            <style>\n",
       "            .fl-table {\n",
       "                margin: 20px;\n",
       "                border-radius: 5px;\n",
       "                font-size: 12px;\n",
       "                border: none;\n",
       "                border-collapse: collapse;\n",
       "                max-width: 100%;\n",
       "                white-space: nowrap;\n",
       "                word-break: keep-all;\n",
       "            }\n",
       "\n",
       "            .fl-table th {\n",
       "                text-align: left;\n",
       "                font-size: 20px;\n",
       "            }\n",
       "\n",
       "            .fl-table tr {\n",
       "                display: table-row;\n",
       "                vertical-align: inherit;\n",
       "                border-color: inherit;\n",
       "            }\n",
       "\n",
       "            .fl-table tr:hover td {\n",
       "                background: #00d1b2;\n",
       "                color: #F8F8F8;\n",
       "            }\n",
       "\n",
       "            .fl-table td, .fl-table th {\n",
       "                border-style: none;\n",
       "                border-top: 1px solid #dbdbdb;\n",
       "                border-left: 1px solid #dbdbdb;\n",
       "                border-bottom: 3px solid #dbdbdb;\n",
       "                border-right: 1px solid #dbdbdb;\n",
       "                padding: .5em .55em;\n",
       "                font-size: 15px;\n",
       "            }\n",
       "\n",
       "            .fl-table td {\n",
       "                border-style: none;\n",
       "                font-size: 15px;\n",
       "                vertical-align: center;\n",
       "                border-bottom: 1px solid #dbdbdb;\n",
       "                border-left: 1px solid #dbdbdb;\n",
       "                border-right: 1px solid #dbdbdb;\n",
       "                height: 30px;\n",
       "            }\n",
       "\n",
       "            .fl-table tr:nth-child(even) {\n",
       "                background: #F8F8F8;\n",
       "            }\n",
       "        </style>\n",
       "        <div id=\"fb6c2de8336643fcb1094e2a2692438a\" class=\"chart-container\" style=\"\">\n",
       "            <p class=\"title\" style=\"color:white\" > 江苏兴荣高新科技股份有限公司-2022-12-22</p>\n",
       "            <p class=\"subtitle\" style=\"font-size: 12px;\" > </p>\n",
       "            <table class=\"etable-click\">\n",
       "    <thead>\n",
       "        <tr>\n",
       "            <th>设备编号</th>\n",
       "            <th>设备名称</th>\n",
       "            <th>工作时间(h)</th>\n",
       "            <th>待机时间(h)</th>\n",
       "            <th>停机时间(h)</th>\n",
       "        </tr>\n",
       "    </thead>\n",
       "    <tbody>\n",
       "        <tr>\n",
       "            <td>DNKLY4032437-A</td>\n",
       "            <td>数控龙门铣床</td>\n",
       "            <td>1.21</td>\n",
       "            <td>4.32</td>\n",
       "            <td>18.47</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032496-A</td>\n",
       "            <td>龙门铣床</td>\n",
       "            <td>0.0</td>\n",
       "            <td>0.0</td>\n",
       "            <td>24.0</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032439-A</td>\n",
       "            <td>数控龙门镗铣床</td>\n",
       "            <td>4.78</td>\n",
       "            <td>0.07</td>\n",
       "            <td>19.15</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032800-A</td>\n",
       "            <td>摇臂钻床</td>\n",
       "            <td>6.76</td>\n",
       "            <td>2.16</td>\n",
       "            <td>15.08</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032489-A</td>\n",
       "            <td>液压平面磨床</td>\n",
       "            <td>6.92</td>\n",
       "            <td>3.57</td>\n",
       "            <td>13.51</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032413</td>\n",
       "            <td>卧式车床</td>\n",
       "            <td>0.0</td>\n",
       "            <td>0.0</td>\n",
       "            <td>24.0</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032407-A</td>\n",
       "            <td>卧式车床</td>\n",
       "            <td>0.97</td>\n",
       "            <td>1.86</td>\n",
       "            <td>21.17</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032192-A</td>\n",
       "            <td>立式升降台铣床</td>\n",
       "            <td>3.46</td>\n",
       "            <td>6.26</td>\n",
       "            <td>14.28</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032155</td>\n",
       "            <td>立式升降台铣床</td>\n",
       "            <td>0.0</td>\n",
       "            <td>0.0</td>\n",
       "            <td>24.0</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032435-A</td>\n",
       "            <td>数控龙门镗铣床</td>\n",
       "            <td>13.41</td>\n",
       "            <td>10.59</td>\n",
       "            <td>0.0</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032416-A</td>\n",
       "            <td>龙门式数控铣镗床</td>\n",
       "            <td>7.87</td>\n",
       "            <td>0.31</td>\n",
       "            <td>15.82</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032764-A</td>\n",
       "            <td>卧式车床</td>\n",
       "            <td>2.51</td>\n",
       "            <td>6.62</td>\n",
       "            <td>14.87</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032178-A</td>\n",
       "            <td>卧式车床</td>\n",
       "            <td>0.0</td>\n",
       "            <td>0.0</td>\n",
       "            <td>24.0</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032432-A</td>\n",
       "            <td>卧式车床</td>\n",
       "            <td>4.73</td>\n",
       "            <td>1.65</td>\n",
       "            <td>17.62</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032492-A</td>\n",
       "            <td>平面磨</td>\n",
       "            <td>0.0</td>\n",
       "            <td>0.0</td>\n",
       "            <td>24.0</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032431-A</td>\n",
       "            <td>立式铣床</td>\n",
       "            <td>0.45</td>\n",
       "            <td>9.27</td>\n",
       "            <td>14.28</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032249-</td>\n",
       "            <td>万能外圆磨床</td>\n",
       "            <td>0.0</td>\n",
       "            <td>0.0</td>\n",
       "            <td>24.0</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032222-A</td>\n",
       "            <td>万能外圆磨床</td>\n",
       "            <td>1.83</td>\n",
       "            <td>3.14</td>\n",
       "            <td>19.03</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DIKLY4041577</td>\n",
       "            <td>数控加工中心</td>\n",
       "            <td>6.24</td>\n",
       "            <td>2.75</td>\n",
       "            <td>15.01</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032146-A</td>\n",
       "            <td>摇臂钻床</td>\n",
       "            <td>7.29</td>\n",
       "            <td>1.16</td>\n",
       "            <td>15.55</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032156-A</td>\n",
       "            <td>摇臂钻床</td>\n",
       "            <td>7.41</td>\n",
       "            <td>2.2</td>\n",
       "            <td>14.39</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032180-A</td>\n",
       "            <td>摇臂钻床</td>\n",
       "            <td>6.84</td>\n",
       "            <td>2.53</td>\n",
       "            <td>14.63</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032145-A</td>\n",
       "            <td>数控车床</td>\n",
       "            <td>0.0</td>\n",
       "            <td>0.0</td>\n",
       "            <td>24.0</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032470-A</td>\n",
       "            <td>数控车床</td>\n",
       "            <td>0.0</td>\n",
       "            <td>0.0</td>\n",
       "            <td>24.0</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4033031-A</td>\n",
       "            <td>数控车床</td>\n",
       "            <td>0.0</td>\n",
       "            <td>0.0</td>\n",
       "            <td>24.0</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DIKLY4041576</td>\n",
       "            <td>数控加工中心</td>\n",
       "            <td>7.08</td>\n",
       "            <td>1.86</td>\n",
       "            <td>15.06</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032644-A</td>\n",
       "            <td>数控车床</td>\n",
       "            <td>7.37</td>\n",
       "            <td>1.5</td>\n",
       "            <td>15.13</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032646-A</td>\n",
       "            <td>数控车床</td>\n",
       "            <td>0.0</td>\n",
       "            <td>0.0</td>\n",
       "            <td>24.0</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032647-A</td>\n",
       "            <td>数显卧式镗床</td>\n",
       "            <td>0.0</td>\n",
       "            <td>0.0</td>\n",
       "            <td>24.0</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4033064-A</td>\n",
       "            <td>数显卧式镗床</td>\n",
       "            <td>24.0</td>\n",
       "            <td>0.0</td>\n",
       "            <td>0.0</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032164-A</td>\n",
       "            <td>卧式车床</td>\n",
       "            <td>6.86</td>\n",
       "            <td>2.96</td>\n",
       "            <td>14.18</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DIKLY4041579</td>\n",
       "            <td>数控加工中心</td>\n",
       "            <td>0.0</td>\n",
       "            <td>8.95</td>\n",
       "            <td>15.05</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032487-A</td>\n",
       "            <td>数控加工中心</td>\n",
       "            <td>8.7</td>\n",
       "            <td>0.0</td>\n",
       "            <td>15.3</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DNKLY4032495-A</td>\n",
       "            <td>数控加工中心</td>\n",
       "            <td>9.59</td>\n",
       "            <td>0.51</td>\n",
       "            <td>13.9</td>\n",
       "        </tr>\n",
       "        <tr>\n",
       "            <td>DIKLY4041578</td>\n",
       "            <td>数控加工中心</td>\n",
       "            <td>0.0</td>\n",
       "            <td>8.96</td>\n",
       "            <td>15.04</td>\n",
       "        </tr>\n",
       "    </tbody>\n",
       "</table>\n",
       "        </div>\n",
       "\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x7f1d5862b828>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " # 生成设备信息表格\n",
    "name_list = cinfos['name'].tolist()\n",
    "equipMentNumber_list = cinfos['equipmentnumber'].tolist()\n",
    "workTime_list = cinfos['worktime'].tolist()\n",
    "standbyTime_list = cinfos['standbytime'].tolist()\n",
    "stopTime_list = cinfos['stoptime'].tolist()\n",
    "\n",
    "headers = ['设备编号', '设备名称', '工作时间(h)', '待机时间(h)', '停机时间(h)']\n",
    "rows = [[equipMentNumber_list[i], name_list[i], workTime_list[i], standbyTime_list[i], stopTime_list[i]] for i in\n",
    "        range(len(equipMentNumber_list))]\n",
    "table = Table()\n",
    "table.add(headers=headers, rows=rows, attributes={\"class\": \"etable-click\"})\n",
    "table.set_global_opts(title_opts=opts.ComponentTitleOpts(title=\"{}-{}\".format(cname, date), title_style={'style': 'color:white'}))\n",
    "table.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "f1599841",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"1af0b4e43732434796ffc27218bf417b\" style=\"width:100%; height:260px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_1af0b4e43732434796ffc27218bf417b = echarts.init(\n",
       "                    document.getElementById('1af0b4e43732434796ffc27218bf417b'), 'white', {renderer: 'canvas'});\n",
       "                var option_1af0b4e43732434796ffc27218bf417b = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#33ffff\",\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"line\",\n",
       "            \"connectNulls\": false,\n",
       "            \"symbolSize\": 4,\n",
       "            \"showSymbol\": true,\n",
       "            \"smooth\": false,\n",
       "            \"clip\": true,\n",
       "            \"step\": false,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    \"DNKLY4032437-A\",\n",
       "                    23.04\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032496-A\",\n",
       "                    0.0\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032439-A\",\n",
       "                    20.21\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032800-A\",\n",
       "                    37.17\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032489-A\",\n",
       "                    43.71\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032413\",\n",
       "                    0.0\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032407-A\",\n",
       "                    11.79\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032192-A\",\n",
       "                    40.5\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032155\",\n",
       "                    0.0\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032435-A\",\n",
       "                    100.0\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032416-A\",\n",
       "                    34.08\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032764-A\",\n",
       "                    38.04\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032178-A\",\n",
       "                    0.0\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032432-A\",\n",
       "                    26.58\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032492-A\",\n",
       "                    0.0\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032431-A\",\n",
       "                    40.5\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032249-\",\n",
       "                    0.0\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032222-A\",\n",
       "                    20.71\n",
       "                ],\n",
       "                [\n",
       "                    \"DIKLY4041577\",\n",
       "                    37.46\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032146-A\",\n",
       "                    35.21\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032156-A\",\n",
       "                    40.04\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032180-A\",\n",
       "                    39.04\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032145-A\",\n",
       "                    0.0\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032470-A\",\n",
       "                    0.0\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4033031-A\",\n",
       "                    0.0\n",
       "                ],\n",
       "                [\n",
       "                    \"DIKLY4041576\",\n",
       "                    37.25\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032644-A\",\n",
       "                    36.96\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032646-A\",\n",
       "                    0.0\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032647-A\",\n",
       "                    0.0\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4033064-A\",\n",
       "                    100.0\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032164-A\",\n",
       "                    40.92\n",
       "                ],\n",
       "                [\n",
       "                    \"DIKLY4041579\",\n",
       "                    37.29\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032487-A\",\n",
       "                    36.25\n",
       "                ],\n",
       "                [\n",
       "                    \"DNKLY4032495-A\",\n",
       "                    42.08\n",
       "                ],\n",
       "                [\n",
       "                    \"DIKLY4041578\",\n",
       "                    37.33\n",
       "                ]\n",
       "            ],\n",
       "            \"hoverAnimation\": true,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"areaStyle\": {\n",
       "                \"opacity\": 0\n",
       "            },\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 0\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"axisLine\": {\n",
       "                \"show\": true,\n",
       "                \"onZero\": true,\n",
       "                \"onZeroAxisIndex\": 0,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\",\n",
       "                    \"color\": \"black\"\n",
       "                }\n",
       "            },\n",
       "            \"axisLabel\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"color\": \"white\",\n",
       "                \"rotate\": -30,\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                \"DNKLY4032437-A\",\n",
       "                \"DNKLY4032496-A\",\n",
       "                \"DNKLY4032439-A\",\n",
       "                \"DNKLY4032800-A\",\n",
       "                \"DNKLY4032489-A\",\n",
       "                \"DNKLY4032413\",\n",
       "                \"DNKLY4032407-A\",\n",
       "                \"DNKLY4032192-A\",\n",
       "                \"DNKLY4032155\",\n",
       "                \"DNKLY4032435-A\",\n",
       "                \"DNKLY4032416-A\",\n",
       "                \"DNKLY4032764-A\",\n",
       "                \"DNKLY4032178-A\",\n",
       "                \"DNKLY4032432-A\",\n",
       "                \"DNKLY4032492-A\",\n",
       "                \"DNKLY4032431-A\",\n",
       "                \"DNKLY4032249-\",\n",
       "                \"DNKLY4032222-A\",\n",
       "                \"DIKLY4041577\",\n",
       "                \"DNKLY4032146-A\",\n",
       "                \"DNKLY4032156-A\",\n",
       "                \"DNKLY4032180-A\",\n",
       "                \"DNKLY4032145-A\",\n",
       "                \"DNKLY4032470-A\",\n",
       "                \"DNKLY4033031-A\",\n",
       "                \"DIKLY4041576\",\n",
       "                \"DNKLY4032644-A\",\n",
       "                \"DNKLY4032646-A\",\n",
       "                \"DNKLY4032647-A\",\n",
       "                \"DNKLY4033064-A\",\n",
       "                \"DNKLY4032164-A\",\n",
       "                \"DIKLY4041579\",\n",
       "                \"DNKLY4032487-A\",\n",
       "                \"DNKLY4032495-A\",\n",
       "                \"DIKLY4041578\"\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"axisLine\": {\n",
       "                \"show\": true,\n",
       "                \"onZero\": true,\n",
       "                \"onZeroAxisIndex\": 0,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\",\n",
       "                    \"color\": \"black\"\n",
       "                }\n",
       "            },\n",
       "            \"axisLabel\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"color\": \"white\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u6700\\u65b0\\u8bbe\\u5907\\u5f00\\u673a\\u7387(%)\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"textStyle\": {\n",
       "                \"color\": \"black\"\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"dataZoom\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"slider\",\n",
       "        \"realtime\": true,\n",
       "        \"start\": 0,\n",
       "        \"end\": 60,\n",
       "        \"orient\": \"horizontal\",\n",
       "        \"zoomLock\": false,\n",
       "        \"filterMode\": \"filter\"\n",
       "    }\n",
       "};\n",
       "                chart_1af0b4e43732434796ffc27218bf417b.setOption(option_1af0b4e43732434796ffc27218bf417b);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x7f1d58b00908>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = Line(init_opts=opts.InitOpts(width='100%', height='260px'))\n",
    "c.add_xaxis(cinfos.equipmentnumber.tolist())\n",
    "c.add_yaxis(\"\", cinfos.startrate.tolist(), color='#33ffff')\n",
    "c.set_global_opts(title_opts=opts.TitleOpts(title=\"最新设备开机率(%)\", title_textstyle_opts={\"color\": \"black\"}),\n",
    "    datazoom_opts=opts.DataZoomOpts(range_start=0, range_end=60),\n",
    "    xaxis_opts=opts.AxisOpts(\n",
    "        axislabel_opts=opts.LabelOpts(rotate=-30, color=\"white\"),\n",
    "        axisline_opts=opts.AxisLineOpts(linestyle_opts=opts.LineStyleOpts(color=\"black\"))\n",
    "    ),\n",
    "    yaxis_opts=opts.AxisOpts(\n",
    "        axislabel_opts=opts.LabelOpts(color=\"white\"),\n",
    "        axisline_opts=opts.AxisLineOpts(linestyle_opts=opts.LineStyleOpts(color=\"black\"))\n",
    "    )\n",
    ")\n",
    "c.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "fd601c79",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "def company_start(cinfos):\n",
    "    cstart = cinfos[\n",
    "        (cinfos['worktime'] != 0) & (cinfos['standbytime'] != 0)]\n",
    "    return cstart"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "25293816",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "cstart = company_start(cinfos)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "cb987ab0",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"6fed1b3ad44a42aeb846c39dab404695\" style=\"width:100%; height:260px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_6fed1b3ad44a42aeb846c39dab404695 = echarts.init(\n",
       "                    document.getElementById('6fed1b3ad44a42aeb846c39dab404695'), 'white', {renderer: 'canvas'});\n",
       "                var option_6fed1b3ad44a42aeb846c39dab404695 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"legendHoverLink\": true,\n",
       "            \"data\": [\n",
       "                13.41,\n",
       "                9.59,\n",
       "                7.87,\n",
       "                7.41,\n",
       "                7.37,\n",
       "                7.29,\n",
       "                7.08,\n",
       "                6.92,\n",
       "                6.86,\n",
       "                6.84\n",
       "            ],\n",
       "            \"showBackground\": false,\n",
       "            \"barMinHeight\": 0,\n",
       "            \"barCategoryGap\": 50,\n",
       "            \"barGap\": \"30%\",\n",
       "            \"large\": false,\n",
       "            \"largeThreshold\": 400,\n",
       "            \"seriesLayoutBy\": \"column\",\n",
       "            \"datasetIndex\": 0,\n",
       "            \"clip\": true,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"itemStyle\": {\n",
       "                \"color\": \"#33ffff\"\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"axisLine\": {\n",
       "                \"show\": true,\n",
       "                \"onZero\": true,\n",
       "                \"onZeroAxisIndex\": 0,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\",\n",
       "                    \"color\": \"black\"\n",
       "                }\n",
       "            },\n",
       "            \"axisLabel\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"color\": \"black\",\n",
       "                \"rotate\": -30,\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                \"DNKLY4032435-A\",\n",
       "                \"DNKLY4032495-A\",\n",
       "                \"DNKLY4032416-A\",\n",
       "                \"DNKLY4032156-A\",\n",
       "                \"DNKLY4032644-A\",\n",
       "                \"DNKLY4032146-A\",\n",
       "                \"DIKLY4041576\",\n",
       "                \"DNKLY4032489-A\",\n",
       "                \"DNKLY4032164-A\",\n",
       "                \"DNKLY4032180-A\"\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"axisLine\": {\n",
       "                \"show\": true,\n",
       "                \"onZero\": true,\n",
       "                \"onZeroAxisIndex\": 0,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\",\n",
       "                    \"color\": \"black\"\n",
       "                }\n",
       "            },\n",
       "            \"axisLabel\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"color\": \"black\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u8bbe\\u5907\\u5de5\\u4f5c\\u65f6\\u957fTOP5\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"textStyle\": {\n",
       "                \"color\": \"black\"\n",
       "            }\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_6fed1b3ad44a42aeb846c39dab404695.setOption(option_6fed1b3ad44a42aeb846c39dab404695);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x7f1da0bb6748>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#设备工作时长TOP5\n",
    "workTimetop = cstart.nlargest(10, 'worktime')\n",
    "x_data = list(workTimetop['equipmentnumber'])\n",
    "y_data = list(workTimetop['worktime'])\n",
    "c = Bar(init_opts=opts.InitOpts(width=\"100%\", height=\"260px\"))\n",
    "c.add_xaxis(xaxis_data=x_data)\n",
    "c.add_yaxis(\"\", y_axis=y_data, category_gap=50, itemstyle_opts=opts.ItemStyleOpts(color='#33ffff'))\n",
    "c.set_global_opts(\n",
    "    title_opts=opts.TitleOpts(\"设备工作时长TOP5\", title_textstyle_opts={\"color\": \"black\"}),\n",
    "    xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=-30, color=\"black\"),\n",
    "        axisline_opts=opts.AxisLineOpts(linestyle_opts=opts.LineStyleOpts(color=\"black\"))\n",
    "    ),\n",
    "    yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(color=\"black\"),\n",
    "        axisline_opts=opts.AxisLineOpts(linestyle_opts=opts.LineStyleOpts(color=\"black\"))\n",
    "    )\n",
    ")\n",
    "c.render_notebook()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
